package references

import (
	"hi-jvm/instructions/base"
	"hi-jvm/rtda"
)

// Check whether object is of given type
type CHECK_CAST struct{ base.Index16Instruction }

func (self *CHECK_CAST) Execute(frame *rtda.Frame) {
	stack := frame.OperandStack
	ref := stack.PopRef()
	stack.PushRef(ref)
	if ref == nil {
		return
	}

	class := frame.GetClass(self.Index)
	if !ref.IsInstanceOf(class) {
		panic("java.lang.ClassCastException")
	}
}

